package com.example.gulimall.common.handler;

import com.example.gulimall.common.enums.ServiceCodeEnum;
import com.example.gulimall.common.utils.ResponseUtil;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.web.access.AccessDeniedHandler;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * <p>@description: 权限异常处理器 </p>
 * <p>@author: JGD </p>
 * <p>@create: 2020/3/12 10:32 </p>
 * <p>@version : 1.0.0
 **/
@Slf4j
public class CustomAccessDeniedHandler implements AccessDeniedHandler {
    @Autowired
    private ObjectMapper objectMapper;

    @Override
    public void handle(HttpServletRequest request, HttpServletResponse response, AccessDeniedException accessDeniedException) {
        log.error("权限不足！", accessDeniedException);
        ResponseUtil.out(response, ResponseUtil.resultMap(ServiceCodeEnum.SERVER_INTERNAL_ERROR.getCode(), "权限不足"));
    }
}
